package com.tianhui.consignortwofei.widget;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.statistics.StatisticsDataInfo;

import java.math.BigDecimal;

/**
 * @author fgs
 * @date 2021/2/24
 * @description
 **/
public class StatisticsDataView extends LinearLayout {
    private TextView allOrderTextView;
    private TextView allDriverTextView;
    private TextView allCarTextView;
    private TextView allAmountTextView;

    public StatisticsDataView(Context context) {
        this(context, null);
    }

    public StatisticsDataView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public StatisticsDataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = LayoutInflater.from(context).inflate(R.layout.layout_statistics_data_view, null);
        LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(10, 10, 10, 10);
        view.setLayoutParams(layoutParams);
        addView(view);

        allOrderTextView = view.findViewById(R.id.layout_statistics_data_view_allOrderTextView);
        allDriverTextView = view.findViewById(R.id.layout_statistics_data_view_allDriverTextView);
        allCarTextView = view.findViewById(R.id.layout_statistics_data_view_allCarTextView);
        allAmountTextView = view.findViewById(R.id.layout_statistics_data_view_allAmountTextView);

    }

    public void setStatisticsViewData(StatisticsDataInfo info) {
        allOrderTextView.setText(info.allOrder);
        allDriverTextView.setText(info.allDriver);
        allCarTextView.setText(info.allCar);
        if (!TextUtils.isEmpty(info.allAmount)) {
            allAmountTextView.setText(new BigDecimal(info.allAmount).toString());
        }
    }
}
